/**
 * 
 */
package nullby.omnia.helper;

import java.util.ArrayList;

import nullby.omnia.R;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * @author Sergey Bandysik </br>[bandysik[at]gmail[dot]com]
 * 
 */
public class DialogHelper extends DialogFragment {

	public enum DIALOG_TYPE {
		BACKGROUND, VIEW, LANG
	}

	private DIALOG_TYPE typeDialog;
	private ListView list;
	private ArrayList<String> objects;
	private ArrayAdapter<CharSequence> adapter;

	/**
	 * @param typeDialog
	 * 
	 */
	public DialogHelper(DIALOG_TYPE typeDialog) {
		this.typeDialog = typeDialog;
	}

	@Override
	public void onActivityCreated(Bundle arg0) {
		super.onActivityCreated(arg0);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
			setStyle(STYLE_NO_TITLE, android.R.style.Theme_Dialog);
		} else {
			setStyle(STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
		}
		
		switch (typeDialog) {
		case BACKGROUND:
			adapter = ArrayAdapter.createFromResource(getActivity(),
					R.array.pref_entries_list_preference_bgcolor,
					R.layout.item_dialog_list);
			break;
		case VIEW:
			adapter = ArrayAdapter.createFromResource(getActivity(),
					R.array.pref_entries_list_preference_view,
					R.layout.item_dialog_list);
			break;
		case LANG:
			adapter = ArrayAdapter.createFromResource(getActivity(),
					R.array.pref_entries_list_preference_lang,
					R.layout.item_dialog_list);
			break;
		default:
			break;
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.view_list, null, false);
		list = (ListView) v.findViewById(R.id.list);
		list.setAdapter(adapter);
		return v;
	}

}
